home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / REDIRECT.ZIP / REDIRECT.DOC
Text File  |  1990-08-18  |  25KB  |  749 lines

  1.  
  2.                        Rerouting, Piping, and EDLIN.
  3.                        -----------------------------
  4.  
  5. A distinguishing mark of MS-DOS / PC-DOS is without doubt the Command Line
  6. Interface. The user types a small line of text, which is in fact a simple
  7. sentence, that may be analyzed and executed by the command interpreter. The
  8. line is characterized by the following structure:
  9.  
  10. OBJECT [subject / SUBJECT LIST] [PARAMETER / PARAMETER LIST]
  11.  
  12. SUBJECT and PARAMETER are optional, and the order may be contrary to the
  13. one shown above. But OBJECT is determinant. Therefore, the Command
  14. Interpreter must be able to recognise it as one of the following:
  15.  
  16. a. an internal command
  17. b. a .COM-file
  18. c. an .EXE-file
  19. d. a .BAT-file
  20.  
  21. In the cases b, c and d, OBJECT must be retrievable through the PATH-string
  22. in the SET-environment. The following facts are true when the command line
  23. is entered correctly:
  24.  
  25. - OBJECT determines what action will be done;
  26. - SUBJECT determines what the action is directed at;
  27. - PARAMETER determines how the action will take place.
  28.  
  29. An example:
  30.  
  31. DIR A: /W
  32.  
  33. OBJECT = DIR
  34. SUBJECT = drive A:
  35. PARAMETER = /W
  36.  
  37. The usage of Rerouting and Piping give the user a means to use another
  38. syntax than the one mentioned above. This is indicated by placing one or
  39. more of the following symbols in the command line:
  40.  
  41. Symbol        effect
  42.  
  43. <             (Rerouting) OBJECT obtains information from an external
  44.               (ASCII-) file
  45.  
  46. >             (Rerouting) the result of the execution of OBJECT, which
  47.               appears on the screen, is sent to an external file or device
  48.  
  49. >>            (Rerouting) as with the former one, the output is now added
  50.               to the external file
  51.  
  52. |             (Piping) more than one OBJECT is used in the command line;
  53.               the output of OBJECT (n) becomes input for OBJECT (n+1).
  54.  
  55. An example:
  56.  
  57. DIR C:\ | FIND "DIR" | SORT > SORTDIRS.LST
  58.  
  59. to make a sorted overview of all the subdirectories under the current one.
  60.  
  61. OBJECT (1)  = DIR
  62. SUBJECT (1) = C:\
  63. OBJECT (2)  = FIND
  64. SUBJECT (2) = "DIR"
  65. OBJECT (3)  = SORT
  66.  
  67. and the same result would have been achieved if the following commands
  68. entered separately:
  69.  
  70. DIR > FIRST.TMP
  71. FIND "DIR" FIRST.TMP > SECOND.TMP
  72. SORT < SECOND.TMP > SORTDIRS.LST
  73. ERASE *.TMP
  74.  
  75. The second line might even be rewritten as:
  76.  
  77. FIND "DIR" < FIRST.TMP > SECOND.TMP
  78.  
  79. and a replacement for the second and the third line might be:
  80.  
  81. TYPE FIRST.TMP | FIND "DIR" | SORT > SORTDIRS.LST
  82.  
  83. without the final result being changed. In this example, SORTDIRS.LST is
  84. neither an OBJECT, SUBJECT or PARAMETER. Grammatically, one might consider
  85. it an adjunct.
  86.  
  87. In most DOS-manuals the description of Rerouting and Piping is limited to
  88. the standard utilities SORT, FIND en MORE. In fact, SORT and MORE can only
  89. be used this way, but FIND can also be used in simple syntaxes as mentioned
  90. above, being the only OBJECT in the command line. But also many other DOS-
  91. utilities may use the feature, because their input and output is managed
  92. through the standard I/O-routine, which allows the use of Redirection and
  93. Piping. Here are some examples. Some will be quite familiar, others may not
  94. be known yet. The familiar ones were added to make the overview a bit more
  95. complete.
  96.  
  97. 1. Symbol >, redirection to the NUL-device:
  98.  
  99. COPY A:*.* B: > NUL
  100.  
  101. This can be used in batch-files, to avoid the usual mess on your screen
  102. that was to be kept clean with the ECHO OFF command.
  103.  
  104. 2. Symbol >, redirection to the NUL-device:
  105.  
  106. ECHO your-own-text
  107. PAUSE > NUL
  108.  
  109. To be used in a batch-file if you want to replace "Strike a key when ready"
  110. with a more suitable message.
  111.  
  112. 3. Symbol <, feeding internal DOS-commands with file input:
  113. First, create a very small file, containing only the ASCII-character 03.
  114. For example, do this by writing the following script BREAK.DBG for DEBUG:
  115.  
  116. BREAK.DBG
  117. ---------
  118. e 100
  119. 3
  120. r cx
  121. 1
  122. n break.fil
  123. w
  124. q
  125.  
  126. and create BREAK.FIL with the command
  127.  
  128. DEBUG < BREAK.DBG
  129.  
  130. Only from within a batch-file, you can now you use the command
  131.  
  132. PAUSE < BREAK.FIL
  133.  
  134. and, when running the program, all you have to do is to press 'Y' to stop
  135. the program or 'N' to let it continue normally. From the DOS-prompt, you
  136. can use the command
  137.  
  138. DIR /P < BREAK.FIL
  139.  
  140. and the directory listing stops right after the first screen.
  141.  
  142. 4. Symbol <, direct input for the SORT-Utility:
  143. If some words are to be sorted alfabetically, one way is to create an
  144. ASCII-file with the COPY CON method, and to sort its contents with
  145.  
  146. SORT < ASCII.FIL > SORTED.TXT
  147.  
  148. or
  149.  
  150. TYPE ASCII.FIL | SORT > SORTED.TXT
  151.  
  152. A faster solution may be the following command:
  153.  
  154. SORT < CON > SORTED.TXT
  155.  
  156. and when input is terminated with Control-Z, the sorted words will be put
  157. into SORTED.TXT.
  158.  
  159. 5. Symbol <, create a temporary batch-file:
  160. Because input from the CON device can be redirected, an amusing experiment
  161. is the following one:
  162.  
  163. MORE < CON
  164.  
  165. which repeats all the lines you type until input is terminated. The lines
  166. are echoed to the CON device, so you can extend this line:
  167.  
  168. MORE < CON | COMMAND
  169.  
  170. After terminating the input with Control-Z the stored commands are
  171. executed. This is not a real batch-file, because there is no possibility
  172. for parameter testing or using the GOTO statement. Keep in mind that the
  173. last line must be an EXIT statement (and don't forget the Carriage return +
  174. Linefeed). An alternative is the statement CTTY CON, but in that case the
  175. second command processor still remains active in memory.
  176.  
  177. 6. Symbol < or |, feeding internal DOS-commands with file input:
  178. When you delete all the files from a subdirectory with
  179.  
  180. DEL *.*
  181.  
  182. a confirmation from CON must be given. But this can be done automatically
  183. if you first create the small file YES.FIL:
  184.  
  185. COPY CON \YES.FIL
  186. Y
  187. ^Z
  188.        1 File(s) copied
  189.  
  190. or:
  191.  
  192. ECHO Y > \YES.FIL
  193.  
  194. and you may now delete all the files from the subdirectory with one of the
  195. following commands:
  196.  
  197. DEL *.* < \YES.FIL
  198.  
  199. or
  200.  
  201. TYPE \YES.FIL | DEL *.*
  202.  
  203. There is a small disadvantage, however. The file YES.FIL occupies one
  204. complete block on your disk, although it contains only a few bytes. If you
  205. look at the second way this file could be created, and the second way it
  206. was combined with the DEL-command, you may conclude that there is another
  207. way to get rid of your files:
  208.  
  209. ECHO Y | DEL *.*
  210.  
  211. and since you are dealing with a subdirectory, an alternative is
  212.  
  213. ECHO Y | DEL .
  214.  
  215. Very fast, and very dangerous indeed. If your DOS is adapted to another
  216. language, another character may be needed instead of the 'Y'.
  217.  
  218. 6. Symbol < or |, feeding internal DOS-commands with file input:
  219. In a similar way, the DATE and TIME command can be feeded with a Carriage
  220. return + Linefeed, if you only want to know the current system date and
  221. time, without changing them. First, create the small file CARRIAGE.RTN:
  222.  
  223. COPY CON \CARRIAGE.RTN
  224. {enter}
  225. ^Z
  226.        1 File(s) copied
  227.  
  228. and the following commands will give you the information:
  229.  
  230. DATE < \CARRIAGE.RTN
  231. TIME < \CARRIAGE.RTN
  232.  
  233. From within a batch-file, you can make simple time reports this way:
  234.  
  235. TIME < CARRIAGE.RTN >> TIME.RPT
  236.  
  237. But again we have the disadvantage of the small file that must always be
  238. available, yet occupying one block on the disk. And again there is a way to
  239. solve the problem. When you enter the command VER (to inform about the DOS-
  240. version), the given output starts with an empty line. So try these two
  241. commands:
  242.  
  243. VER | DATE
  244. VER | TIME
  245.  
  246. For this matter these commands are no faster than the one using a small
  247. disk file, because temporary files are created when using the Piping
  248. option. You can prove this with the following experiment:
  249.  
  250. A:
  251. (remove diskette from drive A:)
  252. VER | DATE
  253.  
  254. and DOS will ask you whether it should Abort, Retry or Ignore, although VER
  255. and DATE don't need disk access when entered separately.
  256.  
  257. 7. Symbol <, data protection with DEBUG:
  258. In the third example an input script for DEBUG was used to create a binary
  259. file. Many beautiful scripts have been made for DEBUG, most of them being
  260. assembler listings for small DOS-utilities. No assembler listing will be
  261. given here, but a way to make confidential files unreadable before erasing
  262. them:
  263.  
  264. COPY CON DESTROY.DBG
  265. F 0 FFFF 8
  266. W
  267. Q
  268. ^Z
  269.        1 File(s) copied
  270.  
  271. The command
  272.  
  273. DEBUG {filename.ext} < DESTROY.DBG
  274.  
  275. entered before the command
  276.  
  277. ERASE {filename.ext}
  278.  
  279. will replace all the characters in {filename.ext} with a Backstep. Even if
  280. somebody unerases the file, the command
  281.  
  282. TYPE {filename.ext}
  283.  
  284. will only advance the cursor one line, as if the file were totally empty.
  285. Some people would prefer replacing all the characters of {filename.ext}
  286. with the ASCII-sign 7 (bell or beep), but I think that this world is
  287. already too noisy. If you want to use this method on a .EXE or a .HEX file,
  288. you should first rename its extension.
  289.  
  290. 8. Symbol < or |, automatic diskette formatting:
  291. Even for programs like FORMAT, Redirection can be useful. First, make an
  292. input script:
  293.  
  294. COPY CON A.FMT
  295. {enter}
  296. N{enter}
  297. ^Z
  298.        1 File(s) copied
  299.  
  300. and, either at the DOS-prompt or from within a batch-file, use the command
  301.  
  302. FORMAT A: < A.FMT
  303.  
  304. or, with the alternative syntax
  305.  
  306. TYPE A.FMT | FORMAT A:
  307.  
  308. If you use DOS 4.00, A.FMT must begin with TWO empty lines, because that
  309. version of FORMAT always asks for a volume label. But you may want to
  310. format a large number of diskettes, all having the same volume label. In
  311. that case, enter the desired label at the second line. Instead, also the
  312. command
  313.  
  314. LABEL A: < A.LBL
  315.  
  316. may be used (you should now be able to write a correct script for the
  317. LABEL-utility).
  318.  
  319. 9. Symbol >, storing batch-file output:
  320. If you start writing an article about DOS with some useful hints, it would
  321. be rather silly to execute a batch-file, and to retype its output into a
  322. text file that becomes a part of your article. Although the output of DOS-
  323. commands can be redirected into a textfile, this won't be possible with
  324. batch-files: the command
  325.  
  326. BATCH > {filename.ext}
  327.  
  328. produces nothing useful. This is where COMMAND.COM helps: just type
  329.  
  330. COMMAND > {filename.ext}
  331.  
  332. and start entering the commands. Type very carefully, because ALL output to
  333. CON is sent to the file. Terminate with the EXIT command, and add the
  334. created {filename.ext} to your article.
  335.  
  336. 10. Symbol |, quick GWBASIC calculations:
  337. In addition to example 5 and example 6, where ECHO was used to pass an
  338. input string to another command, here's one for GWBASIC-lovers:
  339.  
  340. ECHO FOR X = 1 TO 10 : PRINT X, X^2 : NEXT X | GWBASIC
  341.  
  342. The statements are executed immeadiately, and return to system is done
  343. automatically.
  344.  
  345. So, also GWBASIC accepts redirection. This makes it possible to use an
  346. alternative way to run a GWBASIC program from the DOS-prompt, with
  347. automatic return to the system. One way is to put the statement SYSTEM
  348. somewhere in a program line. Another way is to create an additional
  349. textfile RUNFILE.GBI. The extension .GBI is my own idea, it stands for Gw-
  350. Basic-Instructions. If you are familiar with the use of NC.EXT in the
  351. program Norton Commander, you can enter this as a definition:
  352.  
  353. GBI: GWBASIC < !.!
  354.  
  355. The .GBI-file may be created in the following way:
  356.  
  357. COPY CON RUNFILE.GBI
  358. LOAD "MYPROG.BAS"
  359. RUN
  360. SYSTEM
  361. ^Z
  362.        1 File(s) copied
  363.  
  364. and the matching DOS-conmmand will be:
  365.  
  366. GWBASIC < RUNFILE.GBI
  367.  
  368. You can even put the whole program into a .GBI-file, thus combining the
  369. program lines and the instructions:
  370.  
  371. COPY CON SQUARE.GBI
  372. 10 FOR X = 1 TO 10
  373. 20 PRINT X, X^2
  374. 30 NEXT X
  375. RUN
  376. SYSTEM
  377. ^Z
  378.        1 File(s) copied
  379.  
  380. Attention: there is a substantial difference between such a .GBI-file and a
  381. .BAS-file in ASCII. The latter one is really a program that is loaded into
  382. memory, but the .GBI-file is just a set of instructions that start building
  383. the program when the file is being read. You can see this happen if you run
  384. the GWBASIC-program from a .GBI-file: all the lines are copied to the
  385. CON-device. If you run a big program this way, use redirection to NUL:
  386.  
  387. GWBASIC < RUNFILE.GBI > NUL
  388.  
  389. if that doesn't disagree with the program itself. If the GWBASIC-program
  390. requires keyboard input, the trick won't work. But it can be very well used
  391. for small programs which set up your printer, etc.
  392.  
  393.                        -----------------------------
  394.  
  395. So far, so good. Some nice examples have been shown in relationship to
  396. Rerouting and Piping. The following ones will be related to one small but
  397. useful DOS-utility that was not presented yet: the famous (or notoriuos)
  398. line editor EDLIN.
  399.  
  400. To start with some basic knowledge: when editing a text file with EDLIN,
  401. there are two groups of editing comands. The commands in the first group
  402. are entered at the EDLIN-prompt, the asterix. They consist of (line)
  403. numbers and upper- or lowercase letters. The commands in the second group
  404. (function keys, arrow keys, INS and DEL) are used when (re-)editing one
  405. specific line. Let's first spoil the surprise: Both kinds of commands can
  406. be used in an input script for EDLIN, when using the familiar syntax
  407.  
  408. EDLIN EXAMPLE.TXT < INPUT.ED
  409.  
  410. But you should mind some restrictions:
  411. - don't load TSR-programs like CED before using EDLIN, because they disable
  412. the way EDLIN (and DOS) use their command line buffer;
  413. - no If-Then statements are possible, as in macro commands of some very
  414. sophisticated editors. Therefore, some details of EXAMPLE.TXT must be known
  415. in advance;
  416. - some EDLIN-commands may not be used: the QUIT-command and the ?-option in
  417. searching and replacing strings, since they require confirmation from the
  418. CON-device. CON is disabled when using redirection, so this will lock the
  419. system. After the reset, you will notice an unchanged EXAMPLE.TXT and an
  420. empty EXAMPLE.$$$.
  421. - if DOS 4.00 is used, avoid the List and the Page command. If some lines
  422. are too long, again confirmation from CON is required to continue the
  423. scrolling.
  424. All the other EDLIN-commands can be used in any creative way you might
  425. wish. After issuing the command
  426.  
  427. DIR > EXAMPLE.TXT
  428.  
  429. from a subdirectory, the following INPUT.ED removes the initial disk
  430. information and the indication about remaining free bytes
  431.  
  432. INPUT.ED
  433. --------
  434. s..                            ; search string
  435. 1,.d                           ; delete from first to current line
  436. sFile(s)                       ; search string
  437. .,#d                           ; delete from current to last line
  438. e                              ; end
  439.  
  440. In this way, you can cut any block of text from a bigger document, if you
  441. are certain about the strings at the beginning and the end of the block.
  442. For example, if you have marked a piece of EXAMPLE.TXT, beginning and
  443. ending with the unique strings BBBBB resp. EEEEE, here is a way to solve
  444. the problem with EDLIN:
  445.  
  446. HEAD.ED
  447. -------
  448. 1sBBBBB                        ; look for beginning
  449. 1,.d                           ; delete from first to current line
  450. e                              ; end
  451.  
  452. TAIL.ED
  453. -------
  454. 1tEXAMPLE.TXT                  ; load text
  455. 1sEEEEE                        ; look for end mark
  456. .,#d                           ; delete from current to last line
  457. e                              ; end
  458.  
  459. To cut out the block from EXAMPLE.TXT, enter the following commands
  460. directly or from a batch-file:
  461.  
  462. EDLIN EXAMPLE.TXT < HEAD.ED
  463. EDLIN CUT.OUT.TXT < TAIL.ED
  464. COPY EXAMPLE.BAK EXAMPLE.TXT
  465.  
  466. Of course you can, when using a batch-file, experiment freely with
  467. parameter passing, etc.
  468.  
  469. The T-command in TAIL.ED is an interesting one, because it can also load
  470. hidden files, just like the L-command in DEBUG. However, EDLIN cannot write
  471. to a hidden file. But with the T-command you can easily peek into a hidden
  472. AUTOEXEC.BAT by T-ing it into a temporary file (from DOS: EDLIN X.TMP),
  473. which you even don't have to save (use the Q-command).
  474.  
  475. Here's one to duplicate all the lines in EXAMPLE.TXT
  476.  
  477. DOUBLE.ED
  478. ---------
  479. 1,1,1c                         ; duplicate first line
  480. 1,2,#m                         ; move block to end
  481. e                              ; end
  482.  
  483. If the initial EXAMPLE.ED has 10 lines, you might enter from DOS:
  484.  
  485. FOR %T IN (1 2 3 4 5 6 7 8 9 0) DO EDLIN EXAMPLE.TXT < DOUBLE.ED
  486.  
  487. or use less parameters, repeating the command with Function key 3. If you
  488. want to minimize keyboard operations, the number of characters in the
  489. FOR..DO command and the number of F3+{enter} keystrokes should be more or
  490. less equal. 
  491.  
  492. The following two scripts can be used to transform a complete ASCII-text to
  493. upper or lower case.
  494.  
  495. UPPER.ED                    LOWER.ED
  496. --------                    --------
  497. 1,#ra^ZA                    1,#rA^Za
  498. 1,#rb^ZB                    1,#rB^Zb
  499. {etc.}                      {etc.}
  500. {etc.}                      {etc.}
  501. {etc.}                      {etc.}
  502. 1,#ry^ZY                    1,#rY^Zy
  503. 1,#rz^ZZ                    1,#rZ^Zz
  504. e                           e
  505.  
  506. They may be used to fix up the appearance of program source code, or to
  507. change short system messages. These scripts cannot be created with the COPY
  508. CON method, because the first ^Z would become an EOF-marker. They must be
  509. created with EDLIN, or with another editor that can handle the ^Z-marker as
  510. a text character. If a very large text is being converted to upper or lower
  511. case, an extra script must be created that begins with a Write-command (W)
  512. and an Append-command (A) to load the next part of the text:
  513.  
  514. UPPER_1.ED
  515. ----------
  516. W
  517. A
  518. 1,#ra^ZA
  519. 1,#rb^ZB
  520. {etc.}
  521. {etc.}
  522. {etc.}
  523. 1,#ry^ZY
  524. 1,#rz^ZZ
  525. e
  526.  
  527. UPPER_2.ED
  528. ----------
  529. W
  530. A
  531. W
  532. A
  533. 1,#ra^ZA
  534. 1,#rb^ZB
  535. {etc.}
  536. {etc.}
  537. {etc.}
  538. 1,#ry^ZY
  539. 1,#rz^ZZ
  540. e
  541.  
  542. UPPER_3.ED
  543. ----------
  544. W
  545. A
  546. W
  547. A
  548. W
  549. A
  550. 1,#ra^ZA
  551. 1,#rb^ZB
  552. {etc.}
  553. {etc.}
  554. {etc.}
  555. 1,#ry^ZY
  556. 1,#rz^ZZ
  557. e
  558.  
  559. When adding lines to a text, or changing lines, EDLIN must be put into the
  560. input mode. This is done by indicating the concerning line number, which
  561. may be combined with the Insert-command. When the input is done, you can
  562. leave the input mode by pressing Control-C or entering Control-Z (or
  563. Function key 6). When creating the script with EDLIN, use Control-V + C to
  564. build the Break-command. Control-Z can not be put at a line beginning this
  565. way, because EDLIN would return to its command mode. The Control-V method
  566. doesn't work from the DOS-prompt. But there is yet another method to
  567. simulate the Function keys in an input script for EDLIN. Some additional
  568. information is needed to understand this method.
  569.  
  570. If you press an Arrow key, a Function key, a Page Up/Down, Home/End or
  571. Insert/Delete key, a sequence of two characters is sent from the keyboard.
  572. The value of the first one is always zero, the value of the second one (the
  573. extended key code) is different for each key. Only the following keys are
  574. relevant when using EDLIN:
  575.  
  576. KEY    2ND VALUE     2ND CHAR    MEANING
  577.  
  578. F1     59            ;           copy character from input buffer
  579. F2     60            <           copy to next character pressed
  580. F3     61            =           copy rest of input buffer
  581. F4     62            >           delete to next character pressed
  582. F5     63            ?           replace input buffer
  583. F6     64            @           stop input mode, string separator
  584. Left   75            K           move one position to the left
  585. Right  77            M           move one position to the right
  586. Ins    82            R           insert characters into buffer
  587. Del    83            S           delete characters from buffer
  588.  
  589. EDLIN will easily accept a sequence of a zero-character and an extended key
  590. code in an input script. When using the COPY CON method to create such a
  591. script, the extended key codes can be entered normally. And the
  592. zero-character? You cannot enter it with the Alt-key, but from the
  593. DOS-prompt, the 7-th function key solves the problem.
  594.  
  595. Let's assume an EXAMPLE.TXT which contains but one line:
  596.  
  597. "The second word is removed."
  598.  
  599. and that is exactly what EDLIN will automatically do when using the
  600. following INPUT.ED:
  601.  
  602. INPUT.ED
  603. --------
  604. 1                              ; edit first line
  605. {F2}{space}{F4}{space}{F3}     ; copy to space, delete to space, copy rest
  606. e                              ; end
  607.  
  608. in which the second line is entered as:
  609. {F7} < {space} {F7} > {space} {F7} =
  610.  
  611. Now you can start the operation:
  612.  
  613. EDLIN EXAMPLE.TXT < INPUT.ED
  614. End of input file
  615. *1
  616.         1:*The second word is removed.
  617.         1:*The word is removed.
  618. *e
  619.  
  620. Here is another example: Look for the first line containing the string
  621. "QWERTY", and delete the last two characters of that line.
  622.  
  623. INPUT.ED
  624. --------
  625. 1sQWERTY                       ; look for string
  626. .                              ; edit current line
  627. {F3}{Arrow-L}{Arrow-L}         ; copy buffer, step back 2 times
  628. e                              ; end
  629.  
  630. The third line is entered as:
  631. {F7} = {F7} K {F7} K
  632.  
  633. These two examples are only of theoretical interest, of course. But they
  634. show that some very complicated operations can be described in an input
  635. script for EDLIN. I have used this method in the following situation: A
  636. batch-file MYPROG needed to be run several times, each time requiring the
  637. name of a subdirectory as a parameter. Almost every week, some
  638. subdirectories were added or deleted, so there had to be created a flexible
  639. system. Although the command
  640.  
  641. DIR *.
  642.  
  643. may give you a list of subdirectories, it is not possible to use the
  644. command
  645.  
  646. FOR %T IN (*.) DO CALL MYPROG %T
  647.  
  648. because the parameters in as FOR..DO loop must be filenames. The solution
  649. was set up in the following way:
  650.  
  651. STARTER.BAT
  652. -----------
  653. ECHO OFF 
  654. CLS 
  655. DIR | FIND "DIR" > DIRS.LST
  656. EDLIN DIRS.LST < REALDIRS.ED > NUL
  657.  
  658. REALDIRS.ED
  659. -----------
  660. S.. 
  661. 1,.D 
  662.  
  663. STARTER.BAT makes a list of subdirectories, and the directory entries . and
  664. .. are removed by EDLIN, using the script REALDIRS.ED. 
  665.  
  666. Now, the batch-file MYPROG.BAT can be used repeatedly:
  667.  
  668. FOR %T IN (1 2 3 4 5 6 7 8 9 0) DO CALL MYPROG.BAT
  669.  
  670. MYPROG.BAT
  671. ----------
  672. ECHO OFF 
  673. CLS
  674. TYPE DIRS.LST > SUBPROG.BAT
  675. EDLIN SUBPROG.BAT < 1-SELECT.ED > NUL 
  676. EDLIN DIRS.LST < 1-REMOVE.ED > NUL 
  677. SUBPROG
  678.  
  679. Each time, SUBPROG.BAT is replaced with the remaining contents of DIRS.LST.
  680. Only the first line is used, because it contains the crucial information;
  681. i.e. the next directory name. Look at 1-SELECT.ED to see how that is being
  682. transformed into a new subroutine. The script 1-REMOVE.ED is a very simple
  683. one; it only removes the first line of DIRS.LST. In the third line of
  684. 1-SELECT.ED, {INS} was entered as {F7} R, {F2} was entered as {F7} <, and
  685. in the seventh line {F6} was entered as {F7} @.
  686.  
  687. 1-REMOVE.ED
  688. -----------
  689. 1d                             ; remove first line
  690. e                              ; end
  691.  
  692. 1-SELECT.ED
  693. -----------
  694. 2,#d                               ; delete rest of file
  695. 1                                  ; edit first 
  696. {INS}call TESTPARM.BAT {F2}{space} ; put command before directory name
  697. #i                                 ; append (2) other commands
  698. cd \workdir                        ; return to working directory
  699. echo ^G                            ; end signal
  700. {F6}                               ; enter input mode 
  701. e                                  ; quit EDLIN
  702.  
  703. In the file TESTPARM.BAT, which contains the very DOS commands to be
  704. executed, you can check for parameters. If the last line of DIRS.LST is
  705. reached, TESTPARM.BAT receives no parameter, and the job is finished. Look
  706. at the {F2}{space} combination in 1-SELECT.ED; which is meant to avoid
  707. copying the string "<DIR>" into the batch-file line. The < in this string
  708. is, as usual, considered as a redirection symbol, so DOS starts looking for
  709. a file named DIR, containing input for the given command. Maybe there is
  710. some smart way to use a file named DIR... but watch out for the > symbol!
  711. The added commands "cd \workdir" and "echo ^G" were not really used in my
  712. application, but they are shown here as an example how to add extra lines
  713. to SUBPROG.BAT.
  714.  
  715. Finally, the file UPPER.ED will be revisited. The first form could not be
  716. created with the COPY-CON method. If you use the {F7} trick, the COPY-CON
  717. method can be used. The lines are entered as:
  718.  
  719. 1,#ra{F7}@A
  720. 1,#rb{F7}@B
  721. {etc.}
  722. {etc.}
  723. {etc.}
  724. 1,#ry{F7}@Y
  725. 1,#rz{F7}@Z
  726. e
  727.  
  728. Also, the command
  729.  
  730. TYPE UPPER.ED
  731.  
  732. now shows the whole file on the screen. With the first version, it would
  733. stop right after the first Control-Z character.
  734.  
  735.                        -----------------------------
  736.  
  737. This text may have given you a better idea about Redirection and Piping in
  738. MS-DOS / PC-DOS. Some examples may only be interesting from a theoretical
  739. point of view, but so was the technology of aluminium welding, when it was
  740. first discovered. You can now explore your DOS-system to look for more
  741. possibilities. I wish you good luck in finding them all.
  742.  
  743. Utrecht, august 1990,
  744. Jan van Hulten.
  745.  
  746.  
  747.  
  748.